<?php
// +--------------------------------------------------------------------------
// | ZAIYOUDAO [ 载攸道 先顺得常 ] <http://www.zaiyoudao.com>
// +--------------------------------------------------------------------------
// | Copyright © 2009-2016 载攸道 版权所有 <TEL:17090888854>
// +--------------------------------------------------------------------------
// | Project: YiPHP [ 我会的仅仅是偷懒！ ] <http://www.yiphp.com>
// +--------------------------------------------------------------------------
// | Author: 牛很多戒很多不戒 <n@isdce.com> <http://juexue.wang>
// +--------------------------------------------------------------------------

/**
 * phpMyAdmin授权登录
 */
namespace Addon\PHPMyAdmin\Controller;
use Addon\PHPMyAdmin\Controller\CommonController;

/**
 * phpMyAdmin数据管理
 */
class AuthController extends CommonController {
    
	/**
	 * 授权登录
	 */
	public function Login(){
		
		action_log('addon_phpmyadmin_auth_login'); 
		
		
		//如果不是开发者直接不能进入
		if(getUID()!=1){
			 
			echo'no way';
			
			die;
		}
		
		//加密数据库信息
		$phpMyAdmin_username  = encrypt(C('DB_USER'),C('CRYPT_KEY')); //用户名
		$phpMyAdmin_password  = encrypt(C('DB_PWD'),C('CRYPT_KEY')); //用户密码
		$phpMyAdmin_host      = encrypt(C('DB_HOST'),C('CRYPT_KEY')); //数据库地址
		$phpMyAdmin_db_name   = encrypt(C('DB_NAME'),C('CRYPT_KEY')); //数据库名
		$phpMyAdmin_db_prefix = encrypt(C('DB_PREFIX'),C('CRYPT_KEY')); //表前缀
		$phpMyAdmin_crypt_key = encrypt(C('CRYPT_KEY'),getUID()); //key
	
		$time = 3600; //生成时间长度
		//生成临时cookie
		cookie('phpMyAdmin_username',$phpMyAdmin_username,$time);
		cookie('phpMyAdmin_password',$phpMyAdmin_password,$time);
		cookie('phpMyAdmin_host',$phpMyAdmin_host,$time);
		cookie('phpMyAdmin_db_name',$phpMyAdmin_db_name,$time);
		cookie('phpMyAdmin_db_prefix',$phpMyAdmin_db_prefix,$time);
		cookie('phpMyAdmin_crypt_key',$phpMyAdmin_crypt_key,$time);
		
	    $url = $_SERVER['REQUEST_SCHEME'].'://'.$_SERVER['HTTP_HOST'].'/plugin/phpMyAdmin/';
			 
	    redirect($url,0,'');
			 	
		
	}
	
}